package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.RecyclerView;

import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.Violation;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;
import com.jojo.android.zxlib.tool.ZxTimeTool;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2021/1/11 10:31
 */
public class ViolationPublicityAdapter extends BaseRecyclerAdapter<ViolationPublicityAdapter.Holder, Violation> {
    private final String TAG = "ViolationPublicityAdapter";


    public ViolationPublicityAdapter(Context context) {
        super(context);
    }

    @Override
    protected Holder getHolder(View v) {
        return new Holder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_violation;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        if (position == data.size() - 1 && position != 0) {
            holder.bgLayout.setBackgroundResource(R.drawable.corners_bottom_white);
            holder.line.setVisibility(View.GONE);
        } else if (position == 0 && data.size() == 1) {
            holder.bgLayout.setBackgroundResource(R.drawable.corners_white);
            holder.line.setVisibility(View.GONE);
        } else if (position == 0) {
            holder.bgLayout.setBackgroundResource(R.drawable.corners_top_white);
            holder.line.setVisibility(View.VISIBLE);
        } else {
            holder.bgLayout.setBackgroundResource(R.color.white);
            holder.line.setVisibility(View.VISIBLE);
        }

        holder.userTv.setText("违规ID：" + entity.getUserId());
        if (TextUtils.isEmpty(entity.getRemark())) {
            holder.contentTv.setVisibility(View.GONE);
        } else {
            holder.contentTv.setVisibility(View.VISIBLE);
        }
        holder.contentTv.setText("原因：" + entity.getRemark());
        holder.stateTv.setText(entity.getResult());
        holder.date_tv.setText(ZxTimeTool.getTimeStr(entity.getCreateTime()));
    }


    class Holder extends RecyclerView.ViewHolder {

        @BindView(R.id.user_tv)
        TextView userTv;
        @BindView(R.id.content_tv)
        TextView contentTv;
        @BindView(R.id.state_tv)
        TextView stateTv;
        @BindView(R.id.bg_layout)
        ConstraintLayout bgLayout;
        @BindView(R.id.date_tv)
        TextView date_tv;
        @BindView(R.id.line)
        View line;

        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
